·
<script setup>
import { ref, reactive, watch } from "vue"
import { Plus } from "@element-plus/icons-vue"
const props = defineProps(['visiable'])
const emit = defineEmits(['close'])
const acWrap = ref()
const isShow = ref(false)
const form = reactive({
  cargoName: '', //货品名
  wight: "", // 重量
  weightArea: '', // 重量范围
  price: '', // 初始价格
  discount: 0.2, //折扣
  specifications: "", // 规格
  variety: "", // 品种
  descript: "", //描述
  imgs: [

  ],
  originPrice: "",
  inventoryQuantity: "",
  sort: ''
})
const fileList = ref([])
const businessList = ref([
  {
    id: 1,
    businessName: '果塘湖农贸市场',
    cargoNum: 3,
    saled: '500',
    saledMoney: '4000',
    loginName: "18983838484",
    taken: "2000",
    state: "0"
  },
  {
    id: 2,
    businessName: '渝佰滋味',
    cargoNum: 3,
    saled: '500',
    saledMoney: '4000',
    loginName: "18983838484",
    taken: "2000",
    state: "1"
  },
  {
    id: 3,
    businessName: '鲜丰水果',
    cargoNum: 3,
    saled: '500',
    saledMoney: '4000',
    loginName: "18983838484",
    taken: "2000",
    state: "0"
  }
])
const close = () => {
  emit('close')
}
watch(() => props.visiable, (val) => {
  if (!val) Object.assign(form, {
    cargoName: '', //货品名
    wight: "", // 重量
    weightArea: '', // 重量范围
    price: '', // 初始价格
    discount: 0.2, //折扣
    specifications: "", // 规格
    variety: "", // 品种
    descript: "", //描述
    imgs: [

    ],
    originPrice: "",
    inventoryQuantity: "",
    sort: ''
  })
  isShow.value = val
})
</script>

<template>
  <el-dialog v-model="isShow" title="新增" width="600" @close="close">
    <div class="ac-wrap" ref="acWrap">
      <el-form :model="form" label-width="80px" style="max-width: 600px;margin: 30px auto">
        <el-form-item label="商品图片">
          <el-upload v-model:file-list="fileList" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
            list-type="picture-card">
            <el-icon>
              <Plus />
            </el-icon>
          </el-upload>
        </el-form-item>
        <el-form-item label="商品名称">
          <el-input v-model="form.cargoName" placeholder="名称不超过30个字" />
        </el-form-item>
        <el-form-item label="商家">
          <el-select placeholder="请选择" filterable>
            <el-option v-for="bl in businessList" :key="bl.id" :label="bl.businessName" :value="bl.id" />
          </el-select>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="规格">
              <el-input v-model="form.specifications" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计量单位">
              <el-select placeholder="单位">
                <el-option label="个" value="个" />
                <el-option label="箱" value="箱" />
                <el-option label="件" value="件" />
                <el-option label="其他" value="其他" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="品种">
              <el-input v-model="form.variety" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位重量">
              <el-input v-model="form.wight" placeholder="克" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="单价">
              <el-input v-model="form.price" placeholder="金额" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原价">
              <el-input v-model="form.originPrice" placeholder="金额" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="总库存数">
              <el-input v-model="form.inventoryQuantity" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序">
              <el-input v-model="form.sort" placeholder="数字大于0" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="商品描述">
          <el-input v-model="form.desc" type="textarea" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="isShow = false">取消</el-button>
        <el-button type="primary" @click="isShow = false">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped>
.ac-wrap {
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  position: relative;
  background-color: #fff;
  overflow: auto;
  padding: 0 20px;
}
</style>